package com.ttedu.action.manage.banks;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.ttedu.database.model.banks;
import com.ttedu.database.service.BanksService;
import com.ttedu.util.Validator;

@ParentPackage("json-default")
public class BanksAjaxTreeAction extends BanksAction{
	private String message="";
	@Autowired
	private BanksService banksservice;
	@Action(value="/cas/banks_ajaxtree",results={ @Result(name="success",type="json")})
	public String chaptertips_ajaxtree(){
		JSONArray jsonarray=new JSONArray();
		List<banks> listbanks=banksservice.selectAll();
		if(Validator.isNotNull(listbanks)&&listbanks.size()>0){
			for(banks bank:listbanks){
				JSONObject jsonobject=new JSONObject();
				jsonobject.put("id", bank.getId());
				jsonobject.put("pId", bank.getParentid());
				jsonobject.put("name", bank.getName());
				jsonarray.add(jsonobject);
			}
		}
		message=jsonarray.toString();
		return "success";
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
}
